package com.roc.template.exception;

import com.roc.template.base.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName GlobalExceptionHandler
 * @Description: TODO
 * @Author Administrator
 * @Date 2020/7/28 13 41
 * @Version V1.0
 **/
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = {Exception.class, BussinessException.class})
    public Result errorHandler(Exception ex) {

        if (ex instanceof BussinessException) {
            BussinessException bussinessException = (BussinessException)ex;
            return Result.FAILED(bussinessException.getMessage(), bussinessException.getErrorCode());
        }
        log.error("error",ex);
        return Result.FAILED("系统异常", "-1");
    }


}
